﻿using Industry.Framework.Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Web.Http;
using LitJson;

namespace api.onlyle.com.Controllers
{
    public class xingzuoController : ApiController
    {
        // GET api/<controller>
        Industry.Framework.Common.WebClient webClient = new Industry.Framework.Common.WebClient();
        public IEnumerable<string> Get()
        {
            string value = ConfigHelper.GetConfigString("xingzuoapi");
            string reposevalue = Regex.Unescape(webClient.GetHtml(value));
            try
            {
                reposevalue = reposevalue.Substring(reposevalue.IndexOf("=") + 1, reposevalue.Length - reposevalue.IndexOf("=") - 1);
            }
            catch
            {
                reposevalue = "";
            }
            return new string[] { reposevalue };
        }

        // GET api/<controller>/5
        public string Get(string key)
        {
            string json = "";
            string value = ConfigHelper.GetConfigString("xingzuoapi");
            string reposevalue = Regex.Unescape(webClient.GetHtml(value));
            XingZuoModel modle = new XingZuoModel();
            try
            {
                reposevalue = reposevalue.Substring(reposevalue.IndexOf("=") + 1, reposevalue.Length - reposevalue.IndexOf("=") - 1);
                JsonData jsondata = JsonMapper.ToObject(reposevalue.Replace(";", ""));
                modle.All_doc = jsondata[key]["all_doc"].ToString();
                modle.All_love = jsondata[key]["love_doc"].ToString();
                modle.All_work = jsondata[key]["work_doc"].ToString();
                modle.All_money = jsondata[key]["money_doc"].ToString();

                modle.Alldoc_Star = jsondata[key]["all_star"].ToString();
                modle.Work_Star = jsondata[key]["work_star"].ToString();
                modle.Love_Star = jsondata[key]["love_star"].ToString();
                modle.Money_star = jsondata[key]["money_star"].ToString();

                modle.luck_astro = jsondata[key]["luck_astro"].ToString();
                modle.luck_color = jsondata[key]["luck_color"].ToString();
                modle.luck_num = jsondata[key]["luck_num"].ToString();
                modle.luck_azimuth = jsondata[key]["luck_azimuth"].ToString();

                json = JsonMapper.ToJson(modle);
            }
            catch
            {
                json = "[]";
            }
            

            return json;
        }

        // POST api/<controller>
        public void Post([FromBody]string value)
        {
        }

        // PUT api/<controller>/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/<controller>/5
        public void Delete(int id)
        {
        }
    }
}